import java.util.regex.Matcher;
import java.util.regex.Pattern;

/*
 * 	This class represents the algorithm which extracts staff names from the html
 * 	of the ucd computing stafflist page.
 */
public class UCDStrategy implements Strategy 
{

    public UCDStrategy () 
    {
    }

    public Faculty execute (StringBuffer buff) 
    {
    	Faculty ins = new Faculty();
    	//Pattern to match names in the list of the form
    	//title="View user profile.">Tony Veale</a>
    	Pattern ucd = Pattern.compile("\\w+(\\s\\w+){1,4}</(a|strong)>", Pattern.CASE_INSENSITIVE);
    	
    	
    	//Pattern ucd = Pattern.compile("<STRONG>(prof\\.)?(((\\w)*(\\&(\\w)*\\;)?)*(\\s)?)*</strong>",
    		//							Pattern.CASE_INSENSITIVE);
    	
    	//pattern to remove the excess characters
		Pattern removeTags = Pattern.compile("<(\\/)?(\\w)*>",Pattern.CASE_INSENSITIVE);
		
		Matcher rough = ucd.matcher(buff);
		Matcher tags = removeTags.matcher(buff);

		/*
		 * while there are names left,
		 * remove the excess chars,
		 * save as a new person,
		 * add to institute
		 */
		while(rough.find())
		{
			String str = rough.group();
			tags = removeTags.matcher(str);
			str = tags.replaceAll("");
			Person p = new Person(str);
			ins.addStaffMember(p);
		}
		    	
        return ins;
    }

}

